home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1994 December / PSL Monthly Shareware CD-ROM (Public Software Library)(December 1994).bin / prgmming / dos / asm / genkmaca.asm < prev    next >
Assembly Source File  |  1985-05-19  |  16KB  |  607 lines

  1. ;-----------------------------------------------------------------------
  2. ;
  3. ;  Assembly Language Macros  Version 0.1
  4. ;  Written by: Malcolm McCorquodale III  Houston, Texas  713-626-4979
  5. ;
  6. ;  (c) 1984 by Malcolm McCorquodale III  All commercial rights reserved.
  7. ;
  8. ;  This software is distributed using the "FREE-SOFTWARE" concept.
  9. ;  If you find these macros useful send whatever contribution you
  10. ;  deem appropriate to:
  11. ;
  12. ;         Malcolm McCorquodale III
  13. ;         3470 Locke Lane,
  14. ;         Houston Texas 77027.
  15. ;         (713) 626 - 4979
  16. ;
  17. ;-----------------------------------------------------------------------
  18.  
  19. ;;-----------------------------------------------------------------------
  20. ;;
  21. ;;     General Purpose Macros
  22. ;;
  23. ;;-----------------------------------------------------------------------
  24.  
  25. ;;-----------------------------------------------------------------------
  26. ;;
  27. ;; SAVE <p1,..,p8>  Pushes 1 to 8 parameters.
  28. ;;            Parameters p2 through p8 are optional.
  29. ;;
  30. ;;-----------------------------------------------------------------------
  31. SAVE    MACRO    P1,P2,P3,P4,P5,P6,P7,P8
  32.     IRP    X,<P1,P2,P3,P4,P5,P6,P7,P8>
  33. IFNB    <X>
  34.     PUSH   X
  35. ENDIF
  36.     ENDM
  37.     ENDM
  38.  
  39. ;;-----------------------------------------------------------------------
  40. ;;
  41. ;; RESTORE <p1,..,p8>  Pops 1 to 8 parameters.
  42. ;;               Parameters p2 through p8 are optional.
  43. ;;
  44. ;;-----------------------------------------------------------------------
  45. RESTORE MACRO    P1,P2,P3,P4,P5,P6,P7,P8
  46.     IRP    X,<P1,P2,P3,P4,P5,P6,P7,P8>
  47. IFNB    <X>
  48.     POP    X
  49. ENDIF
  50.     ENDM
  51.     ENDM
  52.  
  53. ;;-----------------------------------------------------------------------
  54. ;;
  55. ;; PRINT <msg> - Writes msg on the screen.
  56. ;;
  57. ;;         No registers destroyed.
  58. ;;
  59. ;;-----------------------------------------------------------------------
  60. PRINT    MACRO    MSG        ; Print message on the screen.
  61.     LOCAL    TEXT,PEXIT
  62.     SAVE    DS,DX
  63.     MOV    DX,CS
  64.     MOV    DS,DX
  65.     MOV    DX,OFFSET TEXT
  66.     MOV    AH,9
  67.     INT    21H
  68.     RESTORE DX,DS
  69.     JMP    PEXIT
  70. TEXT    DB    MSG,'$'
  71. PEXIT:
  72.     ENDM
  73.  
  74. ;;-----------------------------------------------------------------------
  75. ;;
  76. ;; The macros below this point have not been fully tested.  MM.
  77. ;;
  78. ;;-----------------------------------------------------------------------
  79. ;;-----------------------------------------------------------------------
  80. ;;
  81. ;; TERMINATE - End program and return to caller.
  82. ;;
  83. ;;-----------------------------------------------------------------------
  84. TERMINATE MACRO         ; End of program.
  85.       INT      20H
  86.       ENDM
  87.  
  88. ;;-----------------------------------------------------------------------
  89. ;;
  90. ;; RWABS <rw>,<drive>,<nofsect>,<beg>
  91. ;;     <rw>       - 'R' for read, 'W' for write.
  92. ;;     <drive>   - drive number.
  93. ;;     <nofsect> - number of sectors to transfer.
  94. ;;     <beg>       - Begining logical sector number.
  95. ;;
  96. ;;     Read and write absolute sectors.
  97. ;;
  98. ;;     Note: 1) Status information is returned in flags, After the
  99. ;;          flags are sampled they should be poped off the stack
  100. ;;          with a POPF.
  101. ;;
  102. ;;           2) DS:DX must point to the DTA before this call.
  103. ;;
  104. ;;-----------------------------------------------------------------------
  105. RWABS    MACRO    RW,DRIVE,NOFSECT,BEG    ; R/W absolute disk sector.
  106.     SAVE    BX,CX,DX
  107.     MOV    AL,DRIVE
  108.     MOV    CX,NOFSECT
  109.     MOV    DX,BEG
  110. IFIDN    <RW>,<'R'>
  111.     INT    25H
  112. ENDIF
  113. IFIDN    <RW>,<'W'>
  114.     INT    26H
  115. ENDIF
  116.     RESTORE DX,CX,BX
  117.     ENDM
  118.  
  119. ;;-----------------------------------------------------------------------
  120. ;;
  121. ;; ADDTODOS <dosend> - Add the current proc to DOS.
  122. ;;
  123. ;;        Note: <dosend> is a label at the highest memory address
  124. ;;          used by your code.
  125. ;;
  126. ;;-----------------------------------------------------------------------
  127. ADDTODOS MACRO    DOSEND        ; Add a procedure to DOS.
  128.     MOV    DX,DOSEND
  129.     INC    DX
  130.     INT    27H
  131.     ENDM
  132.  
  133. ;;-----------------------------------------------------------------------
  134. ;;
  135. ;; DOSRS232 <char>
  136. ;;        Sends or receives a <char> to/from the standard RS232 port.
  137. ;;
  138. ;;        If <char> is specified then it is sent to the RS232 port.
  139. ;;        If <char> is not specified then a character is read into AL.
  140. ;;
  141. ;;        OUTPUT: If receiving data AL will contain the byte received.
  142. ;;
  143. ;;        All registers saved.
  144. ;;
  145. ;;-----------------------------------------------------------------------
  146. DOSRS232 MACRO    CHAR
  147.     SAVE    AH,DL
  148. IFB    <CHAR>
  149.     MOV    AH,3    ; Receive a character from the RS232 port.
  150. ELSE
  151.     MOV    AH,4    ; Send a character to the RS232 port.
  152. ENDIF
  153.     INT    21H
  154.     RESTORE DL,AH
  155.     ENDM
  156.  
  157. ;;-----------------------------------------------------------------------
  158. ;;
  159. ;; PRINT1 <char> - Send <char> to the standard printer.
  160. ;;
  161. ;;           No registers destroyed.
  162. ;;
  163. ;;-----------------------------------------------------------------------
  164. PRINT1    MACRO    CHAR        ; Send a character to the printer.
  165.     SAVE    AH,DL
  166.     MOV    DL,CHAR
  167.     MOV    AH,5
  168.     INT    21H
  169.     RESTORE DL,AH
  170.     ENDM
  171.  
  172. ;;-----------------------------------------------------------------------
  173. ;;
  174. ;; INPUTSTR <len>,<bufoff>,[<bufseg>]
  175. ;;        <len> - Length of input buffer.
  176. ;;        <bufoff> - Offset from <bufseg> to message buffer.
  177. ;;        <bufseg> - Optional segment for input buffer.
  178. ;;
  179. ;;        Input a string ending with a RETURN from the standard
  180. ;;        input device.
  181. ;;
  182. ;;        No registers destroyed except DS:DX which points to
  183. ;;        input buffer on output.
  184. ;;
  185. ;;        On exit: DS:DX will have <bufseg>:<bufoff>.
  186. ;;             Byte 1 of buffer = Size of buffer.
  187. ;;             Byte 2 of buffer = Number of bytes read w/o c/r.
  188. ;;             Byte 3 of buffer = Start of text read.
  189. ;;
  190. ;;-----------------------------------------------------------------------
  191. INPUTSTR MACRO    LEN,BUFOFF,BUFSEG    ; Get a line of text.
  192.     PUSH    AH
  193. IFNB    <BUFSEG>
  194.     MOV    DX,BUFSEG
  195.     MOV    DS,DX
  196. ENDIF
  197.     MOV    DX,BUFOFF
  198.     MOV    [DX],LEN
  199.     MOV    AH,0AH
  200.     INT    21H
  201.     POP    AH
  202.     ENDM
  203.  
  204. ;;-----------------------------------------------------------------------
  205. ;;
  206. ;; POLLSTDIN - Check the status of the standard input device.
  207. ;;
  208. ;;           On exit: AL = 0FFH - Character is available.
  209. ;;                  00H - Character not available.
  210. ;;
  211. ;;           Note: This routine executes an INT 23H if a ctl-brk
  212. ;;             is detected.
  213. ;;
  214. ;;           No registesrs destroyed.
  215. ;;
  216. ;;-----------------------------------------------------------------------
  217. POLLSTDIN MACRO         ; Poll the standard input device.
  218.     PUSH    AH
  219.     MOV    AH,0BH
  220.     INT    21H
  221.     POP    AH
  222.     ENDM
  223.  
  224. ;;-----------------------------------------------------------------------
  225. ;;
  226. ;; CLRSTDIN <func> - Clear standard input buffer then execute
  227. ;;             function <func>.
  228. ;;        <func> may be 1 - Keyboard input.
  229. ;;              6 - Direct Console I/O.
  230. ;;              7 - Direct Console Input w/o Echo.
  231. ;;              8 - Console Input w/o Echo.
  232. ;;              A - Buffered Keyboard Input.
  233. ;;
  234. ;;        No registers destroyed except AX.
  235. ;;
  236. ;;-----------------------------------------------------------------------
  237. CLRSTDIN MACRO    FUNC        ; Clear the standard input device.
  238.     MOV    AL,FUNC
  239.     MOV    AH,0CH
  240.     INT    21H
  241.     ENDM
  242.  
  243. ;;-----------------------------------------------------------------------
  244. ;;
  245. ;; DISKRESET - Flushes all file buffers.
  246. ;;
  247. ;;-----------------------------------------------------------------------
  248. DISKRESET MACRO         ; Reset the disk.
  249.     PUSH    AH
  250.     MOV    AH,0DH
  251.     INT    21H
  252.     POP    AH
  253.     ENDM
  254.  
  255. ;;-----------------------------------------------------------------------
  256. ;;
  257. ;; PICKDRIVE  <drive> - Select the default disk drive.
  258. ;;
  259. ;;            Input: 0 = Drive A, 1 = Drive B, etc.
  260. ;;
  261. ;;            Output: AL = number of drives. Minimum=2.
  262. ;;
  263. ;;            No registers destroyed.
  264. ;;
  265. ;;-----------------------------------------------------------------------
  266. PICKDRIVE MACRO DRIVE        ; Pick the default disk drive.
  267.     SAVE    DL,AH
  268.     MOV    DL,DRIVE
  269.     MOV    AH,0EH
  270.     INT    21H
  271.     RESTORE AH,DL
  272.     ENDM
  273.  
  274. ;;-----------------------------------------------------------------------
  275. ;;
  276. ;; FINDRIVE - Determine the default drive.
  277. ;;
  278. ;;          Output: AL = 0 = Drive A, 1 = Drive B, etc.
  279. ;;
  280. ;;          No registers destroyed except AL.
  281. ;;
  282. ;;-----------------------------------------------------------------------
  283. FINDRIVE MACRO            ; Find the default disk drive.
  284.     PUSH    AH
  285.     MOV    AH,19H
  286.     INT    21H
  287.     POP    AH
  288.     ENDM
  289.  
  290. ;;-----------------------------------------------------------------------
  291. ;;
  292. ;; SETDTA - Set the DTA.
  293. ;;
  294. ;;        On input: DS:DX must poi